import { defineStore } from "pinia";
import { ref } from 'vue';
import { ElLoading } from 'element-plus'

export const useAppStore = defineStore("App", () => {
    const menuStatus = ref(false);
    const collapse = ref(false);
    const AppConfig = ref({
        
    })
    const pathNow = ref('首页');
    const pathTemp = ref([
        {name:'首页',path:'/index'},
        {name:'商品列表',path:'/product/list'},
    ])
    const enums = {
        10: '待审核',
        20: '待支付',
        30: '审核拒绝',
        40: '订单关闭',
        50: '待发货',
        60: '待收货',
        70: '租赁中',
        80: '逾期',
        90: '售后',
        100: '售后完结',
        110: '正常完结'
      }
    const setMenuStatus = (val) => {
        menuStatus.value = val;
        if(!val){
            startLoading()
        }else{
            closeLoading()
        }
    }
    const setCollapse = (val) => {
        collapse.value = val;
    }
    const startLoading = (configs = {}) => {
        const config = {
          lock: true,
          text: '加载中...',
          body:true,
          background: 'rgba(255, 255, 255, 1)'
        }
        
        ElLoading.service(Object.assign(config, configs))
    }
    const closeLoading = () => {
        ElLoading.service().close()
    }
    const setPathNow = (val) => {
        pathNow.value = val;
    }
    const addPathTemp = (val) => {
        console.log(val)
        pathTemp.value.push(val)
    }

    return { enums,addPathTemp,pathNow,setPathNow,pathTemp,collapse,setCollapse,startLoading,closeLoading,menuStatus,setMenuStatus };
})